package persistencia.cliente;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import negocio.cv.Idioma;
import negocio.cv.Tarea;
import persistencia.DACBase;

public class DACTarea extends DACBase{
	
	private Tarea tarea;
	private List<Tarea> tareas;	
	private CallableStatement clstm;
	private ResultSet rs;
	
	public DACTarea(DACBase dacBase){
		super(dacBase);
	}
	
	public List<Tarea> consultarTareas(){
		tareas = new ArrayList<Tarea>();
		try{
			clstm = getConn().prepareCall("{call tareaConsultarTodas()}"); 
			clstm.execute();
			rs = clstm.getResultSet();			
			while (rs.next()) {
				
				tarea = new Tarea();
				tarea.setIdTarea(rs.getInt("idtarea"));
				tarea.setNombre(rs.getString("nombre"));
				tarea.setDescripcion(rs.getString("descripcion"));
								 
				tareas.add(tarea);
            }			           

			rs.close();
			rs = null;
			clstm.close();
            clstm = null;
            
           
		}    
		catch (SQLException ex) {
		    // handle any errors
		    System.out.println("SQLException: " + ex.getMessage());
		    System.out.println("SQLState: " + ex.getSQLState());
		    System.out.println("VendorError: " + ex.getErrorCode());
		    System.out.println("Error en metodo consultarTareas()_DacTarea");
			}
		
	    return tareas;		
	}
	
	public Tarea consultarTarea(int id){
		try{
			clstm = getConn().prepareCall("{call tareaConsultar(?)}"); 
			clstm.setInt("id", id);
			clstm.execute();
			rs = clstm.getResultSet();			
			if (rs.next()) {
				
				tarea =  new Tarea();
				tarea.setIdTarea(rs.getInt("idtarea"));
				tarea.setNombre(rs.getString("nombre"));				
            }			           

			rs.close();
			rs = null;
			clstm.close();
            clstm = null;  
		}    
		catch (SQLException ex) {
		    // handle any errors
		    System.out.println("SQLException: " + ex.getMessage());
		    System.out.println("SQLState: " + ex.getSQLState());
		    System.out.println("VendorError: " + ex.getErrorCode());
		    System.out.println("Error en metodo consultarTarea(?)_DacTarea");
			}
		
	    return tarea;
	}
}
